import kotlin.math.max


//fun test1() {
//    var a = 1  //可变
//    val b = 2  //不可变
//    var c: Int = 1 //指定数据类型(Kotlin有类型推导机制，这里可以不用指明)
//}

fun add1() {

}

fun add2(a: Int, b: Int): Int {
    return a + b
}

fun add3(a: Int, b: Int): Int = a + b

fun add4(a: Int, b: Int) = a + b

fun max1(a: Int, b: Int): Int {
    if(a > b) {
        return a
    }
    return b
}

fun max2(a: Int, b: Int): Int {
    return if(a > b) a else b
}

fun max3(a: Int, b: Int) = if(a > b) a else b

fun ifTest(name: String) {
    if(name == "cyk") println("cyk-1")
    else if(name == "lyj") println("lyj-2")
}

fun whenTest(num: Int) {
    when(num) {
        1 -> println("1")
        2 -> println("2")
        3 -> println("3")
        4 -> println("4")
        else -> println("非法！") //else 可有可无
    }
}

fun whenTest2(name: String) {
    when(name) {
        "1" ->  {
            println("你好1")
            println("你好2")
            println("你好3")
        }
        "2" -> println("我好像作用不大")
        else -> println("非法")
    }
}

fun whenTest3(name: String) {
    when {
        name == "cyk" -> println("男")
        name == "lyj" -> println("女")
        else -> println("emm...")
    }
}

fun test1() {
    val range = 0..10 //前闭后闭
    for(i in range) { //也可以使用 for(i in 0..10)
        print("${i} ")
    }
}

fun test2() {
    for(i in 0 until 10) { //前闭后开 [0, 10)
        print("${i} ")
    }
}

fun test3() {
    for(i in 0 until 10 step 2) {
        print("${i} ")
    }
}

fun test4() {
    for(i in 10 downTo 0) { //前闭后闭
        print("${i} ")
    }
}

class Study {
    fun doHomework() {
        println("做家庭作业")
    }
    fun readBook() {
        println("读书")
    }
}

fun study(study: Study?) {
    if(study != null) {
        study.doHomework()
        study.readBook()
    }
}

fun testLet(study: Study?) {
    //此时通过 ?.就保证了 study 不为空的时候才会执行 let 函数
    study?.let { it ->
        it.doHomework()
        it.readBook()
    }
}

fun printTest() {
    val name = "cyk"
    val age = 20
    println("name: ${if (2 > 1) "cyk" else "lyj"}, age: $age")
}

fun study(age: String = "男", name: String) {
    println("name: $name, age: $age")
}

fun main() {
    study(name = "cyk") //报错
}